package com.haiheng.common.bean

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.Gson
import com.haiheng.library_base.http.HttpResponse

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2022/5/6 0006
 * @Version: 1.0
 */
data class UserReqeBean(
    val result:UserInfoBean? = null
):HttpResponse()

data class UserInfoBean @JvmOverloads  constructor(
    var patronSn:String = "",
    var name:String = "",
    var identityId:String = "",
    var password:String = "",
    var sex:String = "",
    var nation:String = "",
    var address:String = "",
    var message:String = "",
    var borrowedItemCount:Int = 0,//已借数量
    var maxBorrowItemCount:Int = 0,//最大可借数量
    var exceedCount:Int = 0,
    var patronStatusType:Int = -1,
    var needReturnDate:String = "",
    var borrowedItemSnList:List<String> = arrayListOf(),
    var isPatronExist:Boolean = false
) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readString() ?: "",
        parcel.readInt(),
        parcel.readInt(),
        parcel.readInt(),
        parcel.readInt(),
        parcel.readString() ?: "",
        parcel.createStringArrayList() ?: arrayListOf(), // 此处改为使用 createStringArrayList()
        parcel.readByte().toInt() != 0 // 添加这一行来读取新的字段

    )


    // 将UserInfoBean对象写入Parcel
    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(patronSn)
        parcel.writeString(name)
        parcel.writeString(identityId)
        parcel.writeString(password)
        parcel.writeString(sex)
        parcel.writeString(nation)
        parcel.writeString(address)
        parcel.writeString(message)
        parcel.writeInt(borrowedItemCount)
        parcel.writeInt(maxBorrowItemCount)
        parcel.writeInt(exceedCount)
        parcel.writeInt(patronStatusType)
        parcel.writeString(needReturnDate)
        parcel.writeStringList(borrowedItemSnList)
        parcel.writeByte(if (isPatronExist) 1 else 0) // 添加这一行来写入新的字段

    }

    fun  toJson(): String{
        return Gson().toJson(this)
    }

    // 描述对象的特殊对象标志
    override fun describeContents(): Int {
        return 0
    }
    companion object CREATOR : Parcelable.Creator<UserInfoBean> {
        // 从Parcel中创建UserInfoBean对象
        override fun createFromParcel(parcel: Parcel): UserInfoBean {
            return UserInfoBean(parcel)
        }

        // 创建指定长度的UserInfoBean对象数组
        override fun newArray(size: Int): Array<UserInfoBean?> {
            return arrayOfNulls(size)
        }
    }
}